package jllowrey.view;

import java.awt.Graphics;
import java.util.ArrayList;

import javax.swing.JPanel;

import jllowrey.model.DecisionLinesEvent;
import jllowrey.model.Edge;

/**
 * This skeletal code draws the vertical lines. You need to add logic about drawing edges. 
 */
public class DrawingPanel extends JPanel {

	/** DecisionLinesEvent. */
	DecisionLinesEvent decisionLines;

	/**
	 * Create the panel.
	 */
	public DrawingPanel(DecisionLinesEvent m) {
		this.decisionLines = m;
	}

	/**
	 * Draw the decisionLines board here. 
	 */
	@Override
	public void paintComponent(Graphics g) {
		// be sure to do the "right thing" by swing.
		super.paintComponent(g);

		// This draws lines based on width of panel, which is the same width as the choicesPanel
		int width = getWidth()/decisionLines.numChoices;
		int choiceWidth = width-20;
		for (int i = 0; i < decisionLines.numChoices; i++) {
			// make sure to offset lines horizontally by width/2 for proper centering.
			g.drawLine(i*width + choiceWidth/2, 10, i*width + choiceWidth/2, getHeight());
		}

		ArrayList<Edge> edges = null; 
		Edge e = null;
		for (int i = 0 ; i < decisionLines.numChoices-1; i++){
			edges = decisionLines.lines.get(i).getEdges();
			if (edges.size() != 0){
				for (int z = 0 ; z < decisionLines.lines.get(i).getEdges().size(); z++){
					e= edges.get(z);
					g.drawLine((i*width + choiceWidth/2), e.getHeight(), ((i+1)*width+ choiceWidth/2), e.getHeight());

				}
			}
		}

	}
}
